package com.attendance.www.hr.service.impl;

import java.util.List;

import javax.annotation.Resource;

import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
import com.attendance.www.hr.dao.mapper.MainOrganizationsNewMapper;
import com.attendance.www.hr.entitys.MainOrganizationsNew;
import com.attendance.www.hr.entitys.MainOrganizationsNewExample;
import com.attendance.www.hr.service.IMainOrganizationsNewService;
@Service
public class MainOrganizationsNewServiceImpl implements IMainOrganizationsNewService {

	@Resource
	private MainOrganizationsNewMapper mainOrganizationsNewDao;

	/**
	 * 删除机构增量数据
	 */
	@Override
	public boolean deleteMainOrganizationsNew() {
		int record=mainOrganizationsNewDao.deleteByExample(new MainOrganizationsNewExample());
	    if(record<=0) {
			return false;
		}
		return true;
	}
	
	/**
	 * 新增机构增量数据
	 */
	@Override
	public void saveMainOrganizationsNew(List<MainOrganizationsNew> mainOrganizationsNewList) {
		for (int j = 0; j < mainOrganizationsNewList.size(); j++) {
			if(StringUtils.isNotBlank(mainOrganizationsNewList.get(j).getOrganType())) {
				//如果为公司，清空上级编码和名称
				if(mainOrganizationsNewList.get(j).getOrganType().equals("Company")) {
					mainOrganizationsNewList.get(j).setSuperiorCode(null);
					mainOrganizationsNewList.get(j).setSuperiorName(null);
				}
			}
		    mainOrganizationsNewDao.insertSelective(mainOrganizationsNewList.get(j));
		}
	}
	
	/**
	 * 查询机构增量数据
	 */
	@Override
	public List<MainOrganizationsNew> getMainOrganizationsNewList() {
		MainOrganizationsNewExample example=new MainOrganizationsNewExample();
		example.setOrderByClause("organ_code asc");
		List<MainOrganizationsNew> mainOrganizationsNewList =mainOrganizationsNewDao.selectByExample(example);
		return mainOrganizationsNewList;
	}
}
